#ifndef _CORELSYMBOLENGINE_H_
#define _CORELSYMBOLENGINE_H_

#include <string>
#include <vector>
#include <map>
#include <Tlhelp32.h>
#include "CorelDbgHelp.h"

#define GET_CURRENT_CONTEXT(c, contextFlags) \
    do {\
    memset(&c, 0, sizeof(CONTEXT));\
    __asm    call x \
    __asm x: pop eax \
    __asm    mov c.Eip, eax \
    __asm    mov c.Ebp, ebp \
    __asm    mov c.Esp, esp \
    }while(0);

class CCorelSymbolEngine
{
public:
    CCorelSymbolEngine();
    ~CCorelSymbolEngine();

public:
    BOOL Init(BOOL bForceInit);
    BOOL LoadSymbol(HMODULE hModule, LPCSTR szModule);
    void StackTrace(PCONTEXT pContext, size_t uNumOfFrameToSkip, std::wstring& wstrStackTrace);

private:
    std::wstring SymbolSearchPath();
    BOOL AddressToString(PVOID address, std::string& strAddress);
    void ReportError(LPCWSTR lpwszErrorMsg, DWORD dwErrorCode);

private:
    CRITICAL_SECTION m_csLock;
    BOOL m_bInited;
    std::map<std::string, BOOL> m_mapLoadedSymbol;
    CCorelDbgHelp m_kCorelDbgHelp;
};

#endif // _CORELSYMBOLENGINE_H_